#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], c[N];
string b[N];
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        for(int i = 1; i <= n; i++){
            if(i == 1) b[i] = "red", c[i] = 0;
            else{
                b[i] = "red";
                int w = i - 1;
                while(a[w] != a[i] && w > 0) w--;
                if(w == 0) c[i] = 0;
                else c[i] = a[i];
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++) ans += c[i];
        cout << ans << "\n";
    }
    return 0;
}
